package JavaDesign.report_4.t_1;

import java.util.ArrayList;

/**
 * @author zouran
 * createDate：2023/10/18  8:55
 */
public class SeekJobCenter implements Subject {
    String mess;
    boolean changed;
    ArrayList<Observer> personList;

    SeekJobCenter() {
        personList = new ArrayList<Observer>();
        mess = "";
        changed = false;
    }

    public void addObserver(Observer o) {
        if (!(personList.contains(o))) personList.add(o);
    }

    public void deleteObserver(Observer o) {
        if (personList.contains(o)) personList.remove(o);
    }


    public void notifyObservers() {
        if (changed) {
            for (int i = 0; i < personList.size(); i++) { //对每一个观察者
                Observer observer = personList.get(i);
                observer.hearTelephone(mess);
            } //更新数据
            changed = false;
        }
    }

    public void giveNewMess(String str) {//是否是新消息
        if (str.equals(mess))
            changed = false;
        else {
            mess = str;
            changed = true;
        }
    }
}

